package com.xgp.callable;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class CallableTest {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
//        new Thread(new MyThread()).start();
        new Thread(() -> {}).start();

        MyThread thread = new MyThread();
        //适配类
        FutureTask futureTask = new FutureTask(thread);     //结果会缓存，效率高

        new Thread(futureTask,"A").start();

        System.out.println(futureTask.get());   //这个get方法可能产生阻塞，放到最后，或者采取异步调用
    }
}

class MyThread implements Callable<Integer> {

    @Override
    public Integer call() {
        System.out.println("=========");
        return 1024;
    }
}